﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.DAL;
using Hr.Model;

namespace Hr.BLL
{
    public class AttendanceService
    {
         //引入wageDal 层并实例化
        //bll层调用dal层方法，控制器调用bll层方法
        protected AttendanceDAL Attendance = new AttendanceDAL();

        #region 考勤管理模块
        /// <summary>
        /// 获取所有的
        /// </summary>
        /// <returns></returns>
        //public IEnumerable<object> GetAttendanceList()
        //{
        //    return Attendance.GetAttendanceList();
        //}
        public Dictionary<string,object> GetAttendanceList(int page,int limit)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"AttendanceList",Attendance.GetAttendanceList().Skip(limit*(page-1)).Take(limit) },
                {"Count",Attendance.GetAttendanceList().Count() }
            };
            return dt;
        }
        /// <summary>
        /// 新增数据,修改数据
        /// </summary>
        /// <param name="r"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool UpdateAttendance(Attendance_List r, string type,int pk_User)
        {
            Attendance.UpdateAttendance(r, type, pk_User);
            return Attendance.SaveChanges();
        }
        /// <summary>
        /// 根据考勤ID，获取考勤管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Dictionary<string, object> GetAttendanceFullName(int id)
        {
            return Attendance.GetAttendanceFullName(id);//调用Dal层的GetRoleName方法
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Attendance_List GetAttendance(int id)
        {
            return Attendance.GetAttendance(id);//调用Dal层的GetRoleName方法
        }
        /// <summary>
        /// 获取考勤类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetTypeList()
        {
            return Attendance.GetTypeList("Attendance_List").Select(n => new
            {
                n.ID,
                n.TypeName_CHS
            });
        }
        public IEnumerable<object> GetStatusList()
        {
            return Attendance.GetStatusList("Attendance_List").Select(n => new
            {
                n.ID,
                n.StatusName_CHS
            });
        }
        /// <summary>
        /// 根据FullName查询Attendance_List表数据
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> FNameSelectAttendanceList(int page, int limit, string Description)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"AttendanceList",Attendance.FNameSelectAttendanceList(Description).Skip(limit*(page-1)).Take(limit) },
                {"Count",Attendance.FNameSelectAttendanceList(Description).Count() }
            };
            return dt;
        }
        /// <summary>
        /// 删除考勤信息
        /// </summary>
        /// <param name="pk_Name"></param>
        /// <returns></returns>
        public bool DelAttendancedata(int pk_Attendance)
        {
            Attendance.DelAttendancedata(Attendance.GetAttendance(pk_Attendance));
            return Attendance.SaveChanges();
        }
        #endregion

        #region 考勤周报表
        public List<object> GetWeeklyList(DateTime StartTime,DateTime EndTime,string Term)
        {
           return  Attendance.GetWeeklyList(StartTime,EndTime,Term);
        }
        #endregion
        
        #region 考勤周报表
        public List<object> GetmonthlyList(DateTime StartTime, string Term)
        {
            return Attendance.GetmonthlyList(StartTime, Term);
        }
        #endregion
    }
}
